﻿using AutoMapper;
using MediatR;
using RedDragon.Common.Domain.AuthorizeRBAC;
using RedDragon.Common.Dtos;
using RedDragon.Common.Infrastructure.Interface;
using RedDragon.RBAC.API.Application.Common.Client;
using RedDragon.RBAC.ErrorCodeEnum;
using SqlSugar;
using T.Common.Domain.Common;

namespace RedDragon.RBAC.API.Application.Common.Sale
{
    public class ShowSaleHandler : IRequestHandler<ShowSaleCommand, Result>
    {

        private readonly ISqlSugarClient _db;
        /// <summary>
        /// mapper
        /// </summary>
        private readonly IMapper mapper;
        /// <summary>
        /// 客户仓储
        /// </summary>
        public readonly IBaseRepository<Sales> salesRepository;

        /// <summary>
        /// 日志
        /// </summary>
        private readonly ILogger<ShowSaleHandler> logger;
       /// <summary>
       /// 
       /// </summary>
       /// <param name="db"></param>
       /// <param name="mapper"></param>
       /// <param name="salesRepository"></param>
       /// <param name="logger"></param>

        public ShowSaleHandler(ISqlSugarClient db, IMapper mapper, IBaseRepository<Sales> salesRepository, ILogger<ShowSaleHandler> logger)
        {
            this.mapper = mapper;
            this.salesRepository = salesRepository;
            this.logger = logger;
            _db = db;

        }


        /// <summary>
        /// 订单销售列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<Result> Handle(ShowSaleCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var result = new Result();
                var list = await (await salesRepository.GetAll()).Where(x=>x.IsDel==0). ToArrayAsync();
                result.Data = list;
                return result;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
